package de.revdev.llt.module.classroom.utility;

import de.revdev.llt.module.classroom.Participants;
import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 *
 * @author f.lindermaier
 */
@ManagedBean(name = "ClassRoomRoleConverter")
public class ClassRoomRoleConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value == null || value.isEmpty()) {
            return null;
        }
        return Participants.ClassRoomRole.valueOf(value);
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value.toString().equals("")) {
            return "";
        }
        if (value instanceof String) {
            return (String) value;
        }else{
            return ((Participants.ClassRoomRole) value).name();
        }
    }
}
